/**
 * @author fireway
 * @since 2019年 03月 14日 星期四 07:08:03 CST
 */
package net.mindview.util;

public class BasicGenerator<T> implements Generator<T> {
    private Class<T> mType;

    private BasicGenerator(Class<T> type) {
        mType = type;
    }

    /**
     * Produce a Default generator given a type token
     */
    public static <T> Generator<T> create(Class<T> type) {
        return new BasicGenerator<T>(type);
    }

    @Override
    public T next() {
        // Assumes type is a public class
        T ret = null;

        try {
            ret = mType.newInstance();
        } catch (InstantiationException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        }

        return ret;
    }
}
